<template>
  <div class="group_notice_view" v-if="groupNoticeShow" @click.stop.prevent="">
    <div class="g_notice_head">
      <div>群公告</div>
      <img src="static/image/home/close.png" @click.stop.prevent="$emit('update:groupNoticeShow', false)" />
    </div>
    <div class="g_notice_main">
      <template v-for="(item, index) in groupNoticeList">
        <div class="g_notice_item" :key="'groupn_' + index">
          <div class="notice_item_text" v-html="item.VALUE">{{ item.VALUE }}</div>
          <div class="notice_item_file" v-if="item.ATTACHNAME">
            <div class="notice_t_f_l"></div>
            <div class="notice_t_f_r">
              <div class="notice_f_r_text">{{ item.ATTACHNAME }}</div>
              <div class="notice_f_r_size">
                <span class="n_size_text">{{
                    item.ATTACHSIZE | convertByte
                }}</span>
                <span class="n_down_text" @click.stop.prevent="downNoticeFile(item)">下载</span>
              </div>
            </div>
          </div>
          <div class="g_notice_form" >
            <div class="notice_delete" v-if="my_position == 1 || my_position == 2" @click.stop.prevent="delNoticeShow(item)">
              删除
            </div>
            <div v-else></div>
            <div>{{ item.USERNAME }}&nbsp;发表于{{ item.CREATETIME }}</div>
          </div>
        </div>
      </template>
      <div class="add_notice_icon" @click="addNoticeClick" v-if="my_position == 1 || my_position == 2"></div>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  props: ["groupNoticeShow", "groupNoticeList", "my_position"],
  computed: {
    ...mapState([
      "myInfo",
    ]),
  },
  methods: {
    addNoticeClick() {
      this.$emit("addNoticeClick");
    },
    delNoticeShow(item) {
      this.$emit("delNoticeShow", item);
    },
    //公告文件下载
    downNoticeFile(item) {
      let _this = this;
      let initid = this.$func.uuid();
      item.messageId = initid;
      this.$emit("addDownloadList", item);
      //   this.downloadList.push(item);
      let index = item.ATTACHNAME.lastIndexOf("/");
      let str = item.ATTACHNAME.substring(index + 1, item.ATTACHNAME.length);
      let fileName = str.lastIndexOf("."); //取到文件名开始到最后一个点的长度
      let fileNameLength = str.length; //取到文件名长度
      let fileFormat = str.substring(fileName + 1, fileNameLength); //截
      console.log(this.myInfo.id)
      let info = _this.$shell("SaveFileUrl", [
        '_this.myInfo.id',
        this.$store.state.url + "api/v1/oim/file/download.do?id=" + item.ATTACH,
        item.messageId,
        str,
        fileFormat,
        "",
      ]);
      info = JSON.parse(info);
      if (info.return_code == "TRUE") {
        this.$Message.success("文件下载中,请稍后");
        this.$set(item, "loading", true);
      }
    },
  },
};
</script>
<style scoped>
</style>
